<template>
    <view class="share-container">
	  
    <!-- 成功图标 -->
    <view class="success-icon">
	  <image src="/static/org/org-success.png" mode="aspectFit"></image>
    </view>
  
    <!-- 创建成功标题 -->
    <text class="success-title" v-if = "isCreate">创建成功</text>
    <text class="success-title" v-else >加入成功</text>
    <!-- 组织信息 -->
    <view class="org-info" v-if="orgState.detail">
      <view class="info-item">
        <text class="info-title">{{ orgState.detail.name }}</text>
      </view>
      <view class="info-item">
        <text class="info-label">ID: </text>
        <text class="info-value">{{ orgState.detail.codeNo }}</text>
      </view>
      <view class="info-item">
        <text class="info-label">品牌: </text>
        <text class="info-value">{{ orgState.detail.orgInfo.branch }}</text>
      </view>
      <view class="info-item">
        <text class="info-label">详细地址: </text>
        <text class="info-value">{{ orgState.detail.address }}</text>
      </view>
    </view>
	
	<view class="button-section">
      <button class="gvr-yellow-button sharebutton" v-if ="isCreate" @click="handleShare">
		  分享给我的成员</button>
    </view>

    <view v-if="wxIsShow">
    	<page-container :show="wxIsShow" :overlay="false" @beforeleave="beforeleave">
        </page-container>
    </view>
  </view>
</template>

<script setup>
import { ref,reactive, onMounted } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { RouterMethods } from '@/utils/router'
import { orgApi } from '@/service/api'

// 组织状态管理
const orgState = ref({
  detail: null,
  loading: false,
  error: null,
})
const isCreate = ref(false)
const optionsDic = null
// 页面加载
onLoad((options) => {
  console.log(options)
  const id = options?.id 
  //optionsDic = options
  getOrgDetail(id)
  isCreate.value = options?.iscreate === 'true' || options?.iscreate === true
})
onMounted(()=>{
	
})


// 获取组织详情
const getOrgDetail = async (id) => {
  try {
	const result = await orgApi.getOrgDetail(id)
	if(result.code == undefined) {
	  orgState.value.detail = result
	} else {
	  throw new Error(result.message || '获取组织详情失败')
	}
  } catch(err) {
    orgState.value.error = err.message
    uni.showToast({
      title: err.message,
      icon: 'none'
    })
  } finally {
    orgState.value.loading = false
  }
}
//处理微信返回事件
const wxIsShow = ref(true)
const beforeleave = () => {
	wxIsShow.value = false
	uni.switchTab({
	  url: '/pages/index/index'
	})
}

// 处理分享
const handleShare = () => {
  if(!orgState.value.detail) {
    uni.showToast({
      title: '组织信息未加载',
      icon: 'none'
    })
    return
  }
  
  uni.showToast({ 
    title: '分享成功', 
    icon: 'success' 
  })
  setTimeout(() => {
    RouterMethods.toHome()
  }, 1500)
}


</script>

<style scoped>
.share-container {
  min-height: 100vh;
  background-color: #FFFFFF;
  padding: 0 90rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-sizing: border-box;
}
.success-icon {
  margin-top: 86rpx;
  width: 160rpx;
  height: 160rpx;
  margin-bottom: 32rpx;
}

.success-icon image {
  width: 100%;
  height: 100%;
}

.success-title {
  font-family: PingFangSC-Medium;
  font-size: 32rpx;
  color: #000000;
  letter-spacing: 0;
  font-weight: 500;
}

.org-info {
  margin-top: 50rpx;
  width: 100%;
  display: flex;
  flex-direction: column;
}

.info-item {
  display: flex;
  align-items: flex-start;
  margin-top: 10rpx;
}
.info-title {
  font-family: PingFangSC-Medium;
  font-size: 32rpx;
  color: #000000;
  letter-spacing: 0;
  font-weight: 500;
  width: 100%;
}
.info-label {
  font-family: PingFangSC-Regular;
  font-size: 28rpx;
  color: #000000;
  letter-spacing: 0;
  font-weight: 400;
}

.info-value {
  margin-left: 15rpx;
  font-family: PingFangSC-Regular;
  font-size: 28rpx;
  color: #000000;
  letter-spacing: 0;
  font-weight: 400;
  flex: 1;
}

/* 底部按钮区域样式修改 */
.button-section {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding-bottom: env(safe-area-inset-bottom);
  background-color: #FFFFFF;
}

.sharebutton {
  border-radius: 0;
}
</style>